/**
 * 时间相关
 * @date: 2019-12-25

 */
import moment from 'moment';
import { DEFAULT_DATE_FORMAT, DEFAULT_DATETIME_FORMAT, DEFAULT_TIME_FORMAT } from "../constants";
import { newArray } from "./common";
import { getCurrentUser } from "./user";
/**
 * 获取日期(date)格式化字符串
 *
 * @export
 * @returns
 */

export function getDateFormat() {
  var _getCurrentUser = getCurrentUser(),
      _getCurrentUser$dateF = _getCurrentUser.dateFormat,
      dateFormat = _getCurrentUser$dateF === void 0 ? DEFAULT_DATE_FORMAT : _getCurrentUser$dateF;

  return dateFormat;
}
/**
 * 获取日期(dateTime)格式化字符串
 * @export
 * @returns
 */

export function getDateTimeFormat() {
  var _getCurrentUser2 = getCurrentUser(),
      _getCurrentUser2$date = _getCurrentUser2.dateTimeFormat,
      dateTimeFormat = _getCurrentUser2$date === void 0 ? DEFAULT_DATETIME_FORMAT : _getCurrentUser2$date;

  return dateTimeFormat;
}
/**
 * 获取时间(time)格式化字符串
 * @export
 * @returns
 */

export function getTimeFormat() {
  var _getCurrentUser3 = getCurrentUser(),
      _getCurrentUser3$time = _getCurrentUser3.timeFormat,
      timeFormat = _getCurrentUser3$time === void 0 ? DEFAULT_TIME_FORMAT : _getCurrentUser3$time;

  return timeFormat;
}
/**
 * 获取当前设置的时区
 */

export function getTimeZone() {
  var _getCurrentUser4 = getCurrentUser(),
      timeZone = _getCurrentUser4.timeZone;

  return timeZone;
}
/**
 * 生成 antd 的时间禁用支持函数
 * @param {String|Moment} data - 时间日期字符串
 * @param {String} type - 类型，可选 start, end
 */

export function disabledTime(data) {
  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
  var DATE_FORMAT = 'YYYY-MM-DD';
  var timepoint = moment(data);
  var hour = timepoint.hour();
  var minute = timepoint.minute();
  var second = timepoint.second();
  return function (curDate) {
    var curHour = curDate && curDate.hour();
    var curMinute = curDate && curDate.minute();

    if (curDate && curDate.format(DATE_FORMAT) === timepoint.format(DATE_FORMAT)) {
      return {
        disabledHours: function disabledHours() {
          if (type === 'end') {
            if (minute === 0 && second === 0) {
              return newArray(hour, 24);
            }

            return newArray(hour + 1, 24);
          }

          if (minute === 59 && second === 59) {
            return newArray(0, hour + 1);
          }

          return newArray(0, hour);
        },
        disabledMinutes: function disabledMinutes() {
          if (curHour === hour) {
            if (type === 'end') {
              if (second === 0) {
                return newArray(minute, 60);
              }

              return newArray(minute + 1, 60);
            }

            if (second === 59) {
              return newArray(0, minute + 1);
            }

            return newArray(0, minute);
          }

          return [];
        },
        disabledSeconds: function disabledSeconds() {
          if (curHour === hour && curMinute === minute) {
            if (type === 'end') {
              return newArray(second, 60);
            }

            return newArray(0, second + 1);
          }

          return [];
        }
      };
    }
  };
}